﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Elderos.Highlight.Rules;

namespace Elderos.Highlight
{
    public class RandomRanker : IRanker
    {
        private Dictionary<string, int> _featureMap = new Dictionary<string, int>();

        #region Implementation of IRanker

        public IEnumerable<RankingRule> RankingRules
        {
            get { return new List<RankingRule>(); }
        }

#pragma warning disable 1998
        public async void Rank(HighlightResult result)
#pragma warning restore 1998
        {
            foreach (var position in result.Positions.SelectMany(x => x.SubpositionsFlattened))
            {
                int count = position.Entities.Count;
                if (count == 0) continue;
                if (count == 1)
                    position.Winner = position.Entities.First();
                else
                {
                    var random = new Random();
                    int index = random.Next(count - 1);
                    position.Winner = position.Entities[index];
                }
            }
        }

        public Dictionary<string, int> FeatureMap
        {
            get { return _featureMap; }
            private set { _featureMap = value; }
        }

        #endregion
    }
}
